<template>
  <div class="purchase-record">
    <div class="item" v-for="(item, index) in reward" :key="index">
      <div class="left">
        <p class="title">{{item.title}}</p>
        <p class="time">{{item.create_time | formatDate}}</p>
      </div>
      <div class="right">{{item.money}}元</div>
    </div>
  </div>
</template>

<script>

  import { myReward } from '@/api/api'
  import { formatDate } from '@/util/date.js'

  export default {
    components: {
    },
    filters:{
      formatDate(time){
        let date = new Date(time*1000);
        return formatDate(date,'yyyy.MM.dd');
        //此处formatDate是一个函数，将其封装在common/js/date.js里面，便于全局使用
      }
    },
    data () {
      return {
        reward: {},
      }
    },
    created () {
      this.myRewards()
    },
    methods: {
      myRewards() {
        myReward().then((res) => {
          console.log(res)
          this.reward = res.data.info
        }).catch((err) => {
          console.dir(err)
        })
      }
    }
  }
</script>

<style lang="stylus" scoped>
.purchase-record
  width 100%
  height 100vh
  .item
    display flex
    height 7rem
    background-color #fff
    padding 0 1.6rem
    border-bottom 1px solid #e6e6e6
    &:last-child
      border none
    .left
      flex 3
      .title
        font-size 1.5rem
        color #333
        overflow hidden
        white-space nowrap
        text-overflow ellipsis
        line-height 2rem
        height 2rem
        margin-bottom .4rem
        margin-top 1.5rem
        width 25rem
      .time
        color #999
        font-size 1.2rem
        line-height 1.6rem
        height 1.6rem
    .right
      flex 1
      color #FF659B
      font-weight bold
      font-size 1.5rem
      line-height 7rem
      text-align right
</style>
